#include "my_header.h"

unsigned long my_recv_bytes = 0;
unsigned long my_send_bytes = 0;
unsigned long my_conn_ested = 0;

static unsigned long last_recv_bytes = 0;
static unsigned long last_send_bytes = 0;

inline void update_my_recv_bytes(int n)
{
	my_recv_bytes += n;
	last_recv_bytes += n;
}
inline void update_my_send_bytes(int n)
{
	my_send_bytes += n;
	last_send_bytes += n;
}
inline void update_my_conn_ested(int n)
{
	my_conn_ested += n;
}

inline void print_my_counter(unsigned int counters)
{
	static time_t last_print_time = 0;

	time_t cur_time = 0;

	cur_time = time(NULL);

	if(cur_time > last_print_time + 1)
	{
		START_PRINT;
		if(counters & MY_COUNTER_RECV)
		{
			//print recv bytes
			PRINT_MY_COUNTER("recved bytes", my_recv_bytes, "All Byte");
			PRINT_MY_COUNTER("recved bytes rate", last_recv_bytes / (cur_time - last_print_time), "Byte/S");
		}

		if(counters & MY_COUNTER_SEND)
		{
			//print send bytes
			PRINT_MY_COUNTER("sended bytes", my_send_bytes, "All Byte");
			PRINT_MY_COUNTER("sended bytes rate", last_send_bytes / (cur_time - last_print_time), "Byte/S");
		}

		if(counters & MY_COUNTER_CONNED)
		{
			//print connected sessions
			PRINT_MY_COUNTER("connected sessions", my_conn_ested, "Number");
		}
		END_PRINT;
		last_print_time = cur_time;
		last_recv_bytes = 0;
		last_send_bytes = 0;
	}
}


